home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / archie38_1.lha / archie-1.4 / pfs.h < prev    next >
C/C++ Source or Header  |  1995-01-04  |  14KB  |  382 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7.  
  8. #include "copyright.h"
  9.  
  10. #ifdef PCNFS
  11. #include <tklib.h>
  12. #include <tk_errno.h>
  13. #include <sys/nfs_time.h>
  14. #endif
  15. #ifdef VMS
  16. # include <vms.h>
  17. #else /* not VMS */
  18. # ifndef _TYPES_
  19. #  include <sys/types.h>
  20. # endif /* _TYPES_ */
  21. # ifndef IN_H
  22. #  include <netinet/in.h> 
  23. #  define IN_H
  24. # endif
  25. #endif /* VMS */
  26.  
  27. #ifndef NULL
  28. # ifdef MSDOS
  29. #  include <stdio.h>
  30. # else
  31. #  define NULL 0
  32. # endif /* MSDOS */
  33. #endif /* NULL */
  34.  
  35. #define        PFS_RELEASE    "Beta.4.2E"
  36. #define        PFS_SW_ID    "B42E"
  37.  
  38. /* moved up for vdir_init */
  39. #define ZERO(p)        bzero((char *)(p), sizeof(*(p)))
  40.  
  41. /* General Definitions */
  42.  
  43. #define        MAX_PTXT_LEN    1250     /* Max length of PTEXT structure   */
  44. #define        MAX_PTXT_HDR    32       /* Max offset for start            */
  45. #define        P_ERR_STRING_SZ 100     /* Size of error string        */
  46. #define        MAX_VPATH    1024     /* Max length of virtual pathname  */
  47.  
  48. /* Definition of text structure used to pass text around */
  49.  
  50. struct ptext {
  51.     int            length;          /* Length of text (from start)    */
  52.     char        *start;          /* Start of text            */
  53.     char        dat[MAX_PTXT_LEN+2*MAX_PTXT_HDR];/* The data itself */
  54.     unsigned long     mbz;          /* ZERO to catch runaway strings  */
  55.     struct ptext    *previous;        /* Previous element in list       */
  56.     struct ptext    *next;          /* Next element in linked list    */
  57.     int            seq;          /* Sequence Number            */
  58. };
  59.  
  60. typedef struct ptext *PTEXT;
  61. typedef struct ptext PTEXT_ST;
  62.  
  63. /* Request structure: maintains information about server requests */
  64. struct preq {
  65.     int            cid;          /* Connection ID                  */
  66.     short        priority;      /* Connection priority            */
  67.     int            pf_priority;      /* Priority assigned by pri_func  */
  68.     int            recv_tot;      /* Total # of packets received    */
  69.     int            trns_tot;      /* Total # of packets to transmit */
  70.     struct ptext    *cpkt;          /* Current packet being filled in */
  71.     struct ptext    *recv;          /* Received packets               */
  72.     struct ptext    *trns;          /* Transmitted packets            */
  73.     int            rcvd_thru;      /* Received all packets through # */
  74.     struct preq        *previous;        /* Previous element in list       */
  75.     struct preq        *next;          /* Next element in linked list    */
  76.     struct sockaddr_in    fromto;       /* Sender/Destination            */
  77. };
  78.  
  79. typedef struct preq *PREQ;
  80. typedef struct preq PREQ_ST;
  81.  
  82.  
  83. /* Definition of structure containing information on virtual link */
  84.  
  85. struct vlink {
  86.     int            dontfree;      /* Flag: don't free this link     */
  87.     char        *name;          /* Component of path name        */
  88.     char        linktype;      /* L = Link, U = Union, N= Native */
  89.     int            expanded;      /* Has a union link been expanded */
  90.     char        *type;            /* Type of object pointed to      */
  91.     struct vlink    *filters;      /* Filters associated with link   */
  92.     struct vlink    *replicas;      /* Replicas (* see comment below) */
  93.     char        *hosttype;      /* Type of hostname            */
  94.     char        *host;          /* Files physical location        */
  95.     char        *nametype;      /* Type of filename            */
  96.     char        *filename;      /* System level filename        */
  97.     long        version;      /* Version number of destination  */
  98.     long        f_magic_no;      /* File's magic number        */
  99.     struct acl        *acl;          /* ACL for link            */
  100.     long        dest_exp;      /* Expiration for dest of link    */
  101.     long        link_exp;      /* Expiration of link itself      */
  102.     char        *args;          /* Arguments if this is a filter  */
  103.     struct pattrib    *lattrib;      /* Attributes associated w/ link  */
  104.     struct pfile    *f_info;      /* Info to be assoicated w/ file  */
  105.     struct vlink    *previous;        /* Previous elt in linked list    */
  106.     struct vlink    *next;          /* Next element in linked list    */
  107. };
  108.  
  109. typedef struct vlink *VLINK;
  110. typedef struct vlink VLINK_ST;
  111.  
  112. /* * Note that vlink->replicas is not really a list of replicas of the  */
  113. /*   object.  Instead, it is a list of the objects returned during name */
  114. /*   resolution that share the same name as the current object.  Such   */
  115. /*   an object should only be considered a replica if it also shares    */
  116. /*   the same non-zero magic number.                                    */
  117.  
  118. /* Definition of structure continiaing virtual directory information    */
  119.  
  120. struct vdir {
  121.     int            version;      /* Version of local directory fmt  */
  122.     int            inc_native;      /* Include the native directory    */
  123.     long        magic_no;      /* Magic number of current file    */
  124.     struct acl        *dacl;            /* Default acl for links in dir    */
  125.     struct pfile    *f_info;      /* Directory file info             */
  126.     struct vlink    *links;          /* The directory entries         */
  127.     struct vlink    *lastlink;      /* Last directory entry            */
  128.     struct vlink    *ulinks;      /* The entries for union links     */
  129.     struct vdir        *previous;        /* Previous element in linked list */
  130.     struct vdir        *next;          /* Next element in linked list     */
  131. };
  132.  
  133. typedef struct vdir *PVDIR;
  134. typedef struct vdir VDIR_ST;
  135.  
  136. /* Initialize directory */
  137. #define vdir_init(dir)  ZERO(dir)
  138. /* XXX: was
  139.  
  140.   dir->version = 0;     dir->inc_native = 0; \
  141.   dir->magic_no = 0;    dir->f_info = NULL; \
  142.   dir->links = NULL;    dir->lastlink = NULL; \
  143.   dir->ulinks = NULL;   dir->dacl = NULL; \
  144.   dir->previous = NULL; dir->next = NULL;
  145. */
  146.  
  147. #define vdir_copy(d1,d2) d2->version = d1->version; \
  148.                          d2->inc_native = d1->inc_native; \
  149.                          d2->magic_no = d1->magic_no; \
  150.                  d2->f_info = d1->f_info; \
  151.                          d2->links = d1->links; \
  152.                          d2->lastlink = d1->lastlink; \
  153.                          d2->ulinks = d1->ulinks; \
  154.                          d2->dacl = d1->dacl; \
  155.                          d2->previous = d1->previous; \
  156.                          d2->next = d1->next; 
  157.                          
  158. /* Values of ->inc_native in vdir structure */
  159. #define VDIN_REALONLY    -1   /* Include native files, but not . and ..       */
  160. #define VDIN_NONATIVE     0   /* Do not include files from native directory   */
  161. #define VDIN_INCLNATIVE     1   /* Include files from native directory          */
  162. #define VDIN_NATIVEONLY  2   /* All entries in directory are from native dir */
  163. #define VDIN_PSEUDO      3   /* Directory is not real                        */
  164.  
  165.  
  166. /* Definition of structure containing information on a specific file */
  167.  
  168. union avalue {
  169.     char        *ascii;        /* Character string                */
  170.     struct vlink    *link;        /* A link               */
  171. };
  172.  
  173.  
  174. struct pattrib {
  175.     char        precedence;    /* Precedence for link attribute   */
  176.     char        *aname;        /* Name of the attribute           */
  177.     char        *avtype;    /* Type of the attribute value     */
  178.     union avalue    value;        /* Attribute Value                 */
  179.     struct pattrib    *previous;      /* Previous element in linked list */
  180.     struct pattrib    *next;        /* Next element in linked list     */
  181. };
  182.  
  183. typedef struct pattrib *PATTRIB;
  184. typedef struct pattrib PATTRIB_ST;
  185.  
  186. #define     ATR_PREC_OBJECT  'O'   /* Authoritative answer for object */
  187. #define     ATR_PREC_LINK    'L'   /* Authoritative answer for link   */
  188. #define     ATR_PREC_CACHED  'C'   /* Object info cached w/ link      */
  189. #define     ATR_PREC_REPLACE 'R'   /* From link (replaces O)          */
  190. #define     ATR_PREC_ADD     'A'   /* From link (additional value)    */
  191.  
  192. /* **** Incomplete **** */
  193. struct pfile {
  194.     int            version;      /* Version of local finfo format   */
  195.     long        f_magic_no;      /* Magic number of current file    */
  196.     long        exp;          /* Expiration date of timeout      */
  197.     long        ttl;          /* Time to live after reference    */
  198.     long        last_ref;      /* Time of last reference          */
  199.     struct vlink    *forward;      /* List of forwarding pointers     */
  200.     struct vlink    *backlinks;      /* Partial list of back links      */
  201.     struct pattrib    *attributes;      /* List of file attributes         */
  202.     struct pfile    *previous;        /* Previous element in linked list */
  203.     struct pfile    *next;          /* Next element in linked list     */
  204. };
  205.  
  206. typedef struct pfile *PFILE;
  207. typedef struct pfile PFILE_ST;
  208.  
  209. /* Definition of structure contining an access control list entry */
  210.  
  211. struct acl {
  212.     int            acetype;      /* Access Contol Entry type       */
  213.     char        *atype;           /* Authentication type            */
  214.     char        *rights;          /* Rights                         */
  215.     char        *principals;      /* Authorized principals          */
  216.     struct restrict     *restrictions;    /* Restrictions on use            */
  217.     struct acl        *previous;        /* Previous elt in linked list    */
  218.     struct acl        *next;          /* Next element in linked list    */
  219. };
  220. typedef struct acl *ACL;
  221. typedef struct acl ACL_ST;
  222.  
  223. #define ACL_NONE        0         /* Nobody authorized by ths entry */
  224. #define ACL_DEFAULT        1         /* System default                 */
  225. #define ACL_SYSTEM        2         /* System administrator           */
  226. #define ACL_OWNER               3         /* Directory owner                */
  227. #define ACL_DIRECTORY           4         /* Same as directory              */
  228. #define ACL_ANY                 5         /* Any user                       */
  229. #define ACL_AUTHENT             6         /* Authenticated principal        */
  230. #define ACL_LGROUP              7         /* Local group                    */
  231. #define ACL_GROUP               8         /* External group                 */
  232. #define ACL_ASRTHOST            10        /* Check host and asserted userid */
  233. #define ACL_TRSTHOST            11        /* ASRTHOST from privileged port  */
  234.  
  235.  
  236. /* Definition of structure contining access restrictions */
  237. /* for future extensions                                 */
  238. struct restrict {
  239.     struct acl        *previous;        /* Previous elt in linked list    */
  240.     struct acl        *next;          /* Next element in linked list    */
  241. };
  242.  
  243. /* Definitions for send_to_dirsrv */
  244. #define    CLIENT_DIRSRV_TIMEOUT        4    /* time between retries      */
  245. #define CLIENT_DIRSRV_BACKOFF(x)  (2 * x)    /* Backoff algorithm         */
  246. #define CLIENT_DIRSRV_RETRY        3    /* retry this many times     */
  247.  
  248. /* Definitions for rd_vlink and rd_vdir */
  249. #define        SYMLINK_NESTING 10       /* Max nesting depth for sym links */
  250.  
  251. /* Definition fo check_acl */
  252. #define        ACL_NESTING     10       /* Max depth for ACL group nesting */
  253.  
  254. /* Flags for mk_vdir */
  255. #define         MKVD_LPRIV     1   /* Minimize privs for creator in new ACL    */
  256.  
  257. /* Flags for get_vdir */
  258. #define         GVD_UNION      0    /* Do not expand union links              */
  259. #define      GVD_EXPAND     1   /* Expand union links locally             */
  260. #define         GVD_LREMEXP    3   /* Request remote expansion of local links   */
  261. #define         GVD_REMEXP     7   /* Request remote expansion of all links     */
  262. #define         GVD_VERIFY     8    /* Only verify args are for a directory      */
  263. #define      GVD_FIND       16   /* Stop expanding when match is found        */
  264. #define         GVD_ATTRIB    32   /* Request attributes from remote server     */
  265. #define         GVD_NOSORT       64   /* Do not sort links when adding to dir      */
  266.  
  267. /* Flags for rd_vdir */
  268. #define         RVD_UNION      GVD_UNION
  269. #define         RVD_EXPAND     GVD_EXPAND 
  270. #define         RVD_LREMEXP    GVD_LREMEXP
  271. #define         RVD_REMEXP     GVD_REMEXP
  272. #define         RVD_DFILE_ONLY GVD_VERIFY /* Only return ptr to dir file        */
  273. #define      RVD_FIND       GVD_FIND   
  274. #define      RVD_ATTRIB     GVD_ATTRIB
  275. #define         RVD_NOSORT        GVD_NOSORT
  276. #define         RVD_NOCACHE    128
  277.  
  278. /* Flags for add_vlink */
  279. #define         AVL_UNION      1   /* Link is a union link                      */
  280.  
  281. /* Flags for vl_insert */
  282. #define         VLI_NOCONFLICT 0   /* Do not insert links w/ conflicting names  */
  283. #define      VLI_ALLOW_CONF 1   /* Allow links with conflicting names        */
  284. #define         VLI_NOSORT     2   /* Allow conflicts and don't sort            */
  285.  
  286. /* Flags for mapname */
  287. #define      MAP_READWRITE  0   /* Named file to be read and written         */
  288. #define         MAP_READONLY   1   /* Named file to be read only                */
  289.  
  290. /* Flags for modify_acl */
  291. #define         MACL_NOSYSTEM   0x01
  292. #define      MACL_NOSELF     0x02
  293. #define      MACL_DEFAULT    0x08
  294. #define      MACL_SET        0x0C
  295. #define      MACL_INSERT     0x14
  296. #define      MACL_DELETE     0x10
  297. #define      MACL_ADD        0x1C
  298. #define      MACL_SUBTRACT   0x18
  299. #define      MACL_LINK       0x00
  300. #define      MACL_DIRECTORY  0x20
  301. #define      MACL_OBJECT     0x60
  302. #define      MACL_INCLUDE    0x40
  303.  
  304. #define      MACL_OP    (MACL_DEFAULT|MACL_SET|MACL_INSERT|\
  305.              MACL_DELETE|MACL_ADD|MACL_SUBTRACT)
  306.  
  307. #define      MACL_OTYPE (MACL_LINK|MACL_DIRECTORY|MACL_OBJECT|MACL_INCLUDE)
  308.  
  309. /* Flags for dsrdir */
  310. #define DSRD_ATTRIBUTES                      0x1 /* Fill in attributes for links */
  311.  
  312. /* Access methods returned by Pget_am */
  313. #define P_AM_ERROR            0
  314. #define P_AM_FTP            1
  315. #define P_AM_AFTP            2  /* Anonymous FTP  */
  316. #define P_AM_NFS            4
  317. #define P_AM_KNFS            8  /* Kerberized NFS */
  318. #define P_AM_AFS               16
  319.  
  320. /* Return codes */
  321.  
  322. #define        PSUCCESS    0
  323. #define        PFAILURE    255
  324.  
  325. /* Hush up warnings.  */
  326. void vllfree();
  327.  
  328. /* Procedures in libpfs.a */
  329.  
  330. char *pget_wdhost(), *pget_wdfile(), *pget_wd(), *pget_hdhost();
  331. char *pget_hdfile(), *pget_hd(), *pget_rdhost(), *pget_rdfile();
  332. char *pget_dhost(), *pget_dfile(), *pget_vsname(), *nlsindex();
  333. char *sindex(), *strtok(), *nxtline(), *unquote(), *stcopy();
  334. char *stcopyr(), *readheader(), *month_sname();
  335.  
  336. long        asntotime();
  337. void        procquery();
  338.  
  339. PTEXT        ptalloc();
  340. PTEXT        dirsend();
  341. void        ptfree();
  342. void        ptlfree();
  343.  
  344. PREQ        pralloc();
  345. PREQ        get_next_request();
  346.  
  347. VLINK        rd_slink();
  348. VLINK        rd_vlink();
  349. VLINK        vl_delete();
  350. VLINK        vlalloc();
  351. VLINK        vlcopy();
  352. void        vlfree();
  353.  
  354. PFILE        pfalloc();
  355.  
  356. PATTRIB         parse_attribute();
  357. PATTRIB         atalloc();
  358. PATTRIB     pget_at();
  359. void        atfree();
  360. void        atlfree();
  361.  
  362. ACL             acalloc();
  363. ACL             get_acl();
  364.  
  365. void        stfree();
  366.  
  367. /* Miscellaneous useful definitions */
  368. #ifndef TRUE
  369. #define TRUE        1
  370. #define FALSE        0
  371. #endif
  372.  
  373. #define AUTHORIZED      1
  374. #define NOT_AUTHORIZED  0
  375. #define NEG_AUTHORIZED  -1
  376.  
  377. #ifndef NULL
  378. #define NULL        0
  379. #endif
  380.  
  381. #define FAILED        -1
  382.